
create function Tinh_phi (@LoaiGiaoDich char(6), @SoTien money)
returns money
as
begin
	declare @TienPhi money
	declare @SoTienToiDa money
	declare @SoTienToiThieu money
	declare @PhanTram float
	select @SoTienToiThieu = SoTienToiThieu, @SoTienToiDa = SoTienToiDa, @PhanTram = PhanTram
		from PHI_DICH_VU where MaLoaiGD = @LoaiGiaoDich
	set @TienPhi = @SoTien * @PhanTram
	if  ( @TienPhi < @SoTienToiThieu )
	begin
		set @TienPhi = @SoTienToiThieu
	end
	if  ( @TienPhi > @SoTienToiDa )
	begin
		set @TienPhi = @SoTienToiDa
	end
return @TienPhi
end
